package leetcode_2501_2600;

import java.util.Arrays;

public class LeeCode_2547 {
    public static void main(String[] args) {

    }
    private static int minCost(int[] nums, int k) {
        int n = nums.length;
        int[] f = new int[n + 1];
        int[] state = new int[n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(state, 0);
            int mn = Integer.MAX_VALUE, unique = 0;
            for(int j = i; j >= 0; j--){
                int x = nums[j];
                if (state[x] == 0){
                    state[x]++;
                    unique++;
                }else if (state[x] == 1){
                    state[x]++;
                    unique--;
                }
                mn = Math.min(mn, f[j] - unique);
            }
            f[i + 1] = mn + k;
        }
        return f[n] + n;
    }
}
